//
//  SupplierChooseCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/29.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "SupplierChooseCell.h"

@interface SupplierChooseCell ()

@property (nonatomic, strong) UIImageView *logoImgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *codeLab;
@property (nonatomic, strong) UILabel *KPITitleLab;
@property (nonatomic, strong) UILabel *KPILab;
@property (nonatomic, strong) UILabel *allowTitleLab;
@property (nonatomic, strong) UILabel *allowLab;
@property (nonatomic, strong) UILabel *lineLab;

@end

@implementation SupplierChooseCell

+ (instancetype)SupplierChooseCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"SupplierChooseCell";
    SupplierChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SupplierChooseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.logoImgView = [UIImageView new];
        self.logoImgView.layer.masksToBounds = YES;
        self.logoImgView.layer.cornerRadius = 6;
        self.logoImgView.backgroundColor = Color_Separator;
        [self.contentView addSubview:self.logoImgView];
        
        self.nameLab = [UILabel new];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = BoldFontOfSize(18);
        [self.contentView addSubview:self.nameLab];
        
        self.codeLab = [UILabel new];
        self.codeLab.textColor = HexColor(0x9C9DB3);
        self.codeLab.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.codeLab];
        
        self.KPITitleLab = [UILabel new];
        self.KPITitleLab.textColor = HexColor(0x9C9DB3);
        self.KPITitleLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.KPITitleLab];
        
        self.KPILab = [UILabel new];
        self.KPILab.textColor = HexColor(0x2B2C44);
        self.KPILab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.KPILab];
        
        self.allowTitleLab = [UILabel new];
        self.allowTitleLab.textColor = HexColor(0x9C9DB3);
        self.allowTitleLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.allowTitleLab];
        
        self.allowLab = [UILabel new];
        self.allowLab.textColor = HexColor(0x2B2C44);
        self.allowLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.allowLab];
        
        self.lineLab = [UILabel new];
        self.lineLab.backgroundColor = HexColor(0xF2F2F5);
        [self.contentView addSubview:self.lineLab];
    }
    return self;
}

-(void)setModel:(SupplierMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.logoImgView.frame = CGRectMake(15, 15, 48, 48);
    [self.logoImgView sd_setImageWithURL:[NSURL URLWithString:self.model.headimg]];
    
    self.nameLab.text = self.model.name;
    [self.nameLab sizeToFit];
    self.nameLab.nim_left = self.logoImgView.nim_right + 15;
    self.nameLab.nim_top = self.logoImgView.nim_top;
    
    
    self.codeLab.text = self.model.control_no;
    [self.codeLab sizeToFit];
    
    self.nameLab.nim_width = ScreenW - 15 - self.codeLab.nim_width - 10 - self.nameLab.nim_left;
    self.codeLab.nim_left = self.nameLab.nim_right + 10;
    self.codeLab.nim_bottom = self.nameLab.nim_bottom;
    
    self.KPITitleLab.text = @"KPI得分：";
    [self.KPITitleLab sizeToFit];
    self.KPITitleLab.nim_left = self.nameLab.nim_left;
    self.KPITitleLab.nim_top = self.nameLab.nim_bottom + 5;
    
    self.KPILab.text = self.model.kpi;
    [self.KPILab sizeToFit];
    self.KPILab.nim_left = self.KPITitleLab.nim_right;
    self.KPILab.nim_centerY = self.KPITitleLab.nim_centerY;
    
    self.allowTitleLab.text = @"无合同调度：";
    [self.allowTitleLab sizeToFit];
    self.allowTitleLab.nim_left = self.nameLab.nim_left;
    self.allowTitleLab.nim_top = self.KPITitleLab.nim_bottom + 5;
    
    self.allowLab.text = self.model.id_allow == 2 ? @"允许" : @"不允许";
    [self.allowLab sizeToFit];
    self.allowLab.nim_left = self.allowTitleLab.nim_right;
    self.allowLab.nim_centerY = self.allowTitleLab.nim_centerY;
    
    self.lineLab.frame = CGRectMake(15, self.allowTitleLab.nim_bottom + 14, ScreenW - 15, 1);
    
    self.height = self.lineLab.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
